﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    public Rigidbody2D rigidbody2DBird;
    public Animator animator;
    public bool Death=false;

    public delegate void DeathNotify();
    public event DeathNotify OnDeath;
    // Start is called before the first frame update
    void Start()
    {
        // 暂停动画
      
         Idea();
        // 暂停动画
        InitPos = transform.position;
    }
    private Vector3 InitPos;
    public void Init()
    {
        Death = false;
        transform.position = InitPos;
        Idea();
    }

    public float forceY;
    // Update is called once per frame
    void Update()
    {
        if (Death)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
         
            rigidbody2DBird.velocity = Vector2.zero;
            rigidbody2DBird.AddForce(new Vector2(0, forceY), ForceMode2D.Force);
        }

    }
    public void Flay()
    {
       
        rigidbody2DBird.simulated = true;
        animator.SetTrigger("Flay");

    }
    public void Idea()
    {
        // 停止施加力
      
      
        rigidbody2DBird.simulated = false;
        animator.SetTrigger("Idea");

    }
    public void Die()
    {
        Death = true;
        if (OnDeath!=null)
        {
            OnDeath();
        }
    }
    public void OnCollisionEnter2D(Collision2D collision)
    {
        Die();
        Idea();
    }
    public void OnTriggerEnter2D(Collider2D collision)
    {
        Die();
        Idea();
        Debug.Log("加分");
    }

  
}
